package me.zhengjie.modules.backcard.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.modules.backcard.domain.Backcard;
import me.zhengjie.modules.backcard.service.BackcardService;
import me.zhengjie.modules.backcard.service.dto.BackcardDto;
import me.zhengjie.modules.backcard.service.dto.BackcardQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author lida
* @date 2022-04-28
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "银行卡管理管理")
@RequestMapping("/api/backcard")
public class BackcardController {

    private final BackcardService backcardService;

    @GetMapping
    @Log("查询银行卡管理")
    @ApiOperation("查询银行卡管理")
    @PreAuthorize("@el.check('backcard:list')")
    public ResponseEntity query(BackcardQueryParam query, Pageable pageable){
        return new ResponseEntity<>(backcardService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增银行卡管理")
    @ApiOperation("新增银行卡管理")
    @PreAuthorize("@el.check('backcard:add')")
    public ResponseEntity create(@Validated @RequestBody BackcardDto resources){
        return new ResponseEntity<>(backcardService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改银行卡管理")
    @ApiOperation("修改银行卡管理")
    @PreAuthorize("@el.check('backcard:edit')")
    public ResponseEntity update(@Validated @RequestBody BackcardDto resources){
        backcardService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除银行卡管理")
    @ApiOperation("删除银行卡管理")
    @PreAuthorize("@el.check('backcard:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        backcardService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出银行卡管理")
    @ApiOperation("导出银行卡管理")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('backcard:list')")
    public void download(HttpServletResponse response, BackcardQueryParam query) throws IOException {
        backcardService.download(backcardService.queryAll(query), response);
    }*/

}
